```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>并发编程基础 - 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
            color: #1e293b;
        }
        .code-block {
            background-color: #0f172a;
            color: #e2e8f0;
            border-radius: 0.5rem;
            overflow-x: auto;
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .comparison-table {
            border-collapse: separate;
            border-spacing: 0;
            width: 100%;
        }
        .comparison-table th, .comparison-table td {
            padding: 1rem;
            text-align: left;
            border-bottom: 1px solid #e2e8f0;
        }
        .comparison-table th {
            background-color: #f1f5f9;
            font-weight: 600;
        }
        .comparison-table tr:hover td {
            background-color: #f8fafc;
        }
        .divider {
            height: 1px;
            background: linear-gradient(to right, transparent, #cbd5e1, transparent);
            margin: 2rem 0;
        }
        .feature-icon {
            color: #3b82f6;
            font-size: 1.5rem;
            margin-bottom: 1rem;
        }
        .animated-underline {
            position: relative;
            display: inline-block;
        }
        .animated-underline::after {
            content: '';
            position: absolute;
            width: 100%;
            height: 2px;
            bottom: -2px;
            left: 0;
            background-color: #3b82f6;
            transform: scaleX(0);
            transition: transform 0.3s ease;
        }
        .animated-underline:hover::after {
            transform: scaleX(1);
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6">并发编程基础</h1>
                    <p class="text-xl mb-8 opacity-90">掌握多线程编程的艺术，构建高性能应用</p>
                    <div class="flex flex-wrap gap-4">
                        <a href="#overview" class="bg-white text-blue-800 px-6 py-3 rounded-lg font-medium hover:bg-blue-50 transition duration-300">
                            <i class="fas fa-book-open mr-2"></i> 开始学习
                        </a>
                        <a href="#examples" class="border border-white text-white px-6 py-3 rounded-lg font-medium hover:bg-white hover:bg-opacity-10 transition duration-300">
                            <i class="fas fa-code mr-2"></i> 代码示例
                        </a>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="relative">
                        <div class="w-64 h-64 md:w-80 md:h-80 bg-blue-500 rounded-full opacity-20 absolute -top-4 -left-4"></div>
                        <div class="w-64 h-64 md:w-80 md:h-80 bg-blue-600 rounded-full opacity-20 absolute -bottom-4 -right-4"></div>
                        <img src="https://cdn.nlark.com/yuque/0/2025/png/21449790/1735977181134-5804ab80-9e04-4903-8d24-705aaf7e78fe.png" 
                             alt="并发编程概念图" 
                             class="relative z-10 rounded-lg shadow-xl w-full max-w-md">
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl py-12 px-4 md:px-0">
        <!-- Overview Section -->
        <section id="overview" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-2 h-10 bg-blue-600 mr-4"></div>
                <h2 class="text-3xl font-bold">并发编程概述</h2>
            </div>
            
            <p class="text-lg mb-6">并发编程是指在同一时间段内，多个任务或进程在同一系统中同时执行的技术。通过并发编程，我们能够有效地利用多核处理器，提升系统的响应速度和执行效率。在现代计算机硬件的多核时代，充分利用并发资源已成为构建高效系统的重要手段。</p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-bolt"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">并发与并行的区别</h3>
                    <p><strong>并发（Concurrency）</strong>：指的是在同一时间段内管理多个任务，但并不一定是同时执行。多个任务可以在同一个处理器上交替执行（时间片轮转），甚至是通过操作系统调度进行切换。</p>
                    <p class="mt-4"><strong>并行（Parallelism）</strong>：是指在多个处理器核心或处理单元上同时执行多个任务。并行程序强调任务同时进行，并且每个任务通常在不同的CPU核心上独立运行。</p>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-exclamation-triangle"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">并发编程的挑战</h3>
                    <ul class="space-y-2">
                        <li><i class="fas fa-circle text-blue-500 mr-2 text-xs"></i> 共享资源的竞争</li>
                        <li><i class="fas fa-circle text-blue-500 mr-2 text-xs"></i> 死锁问题</li>
                        <li><i class="fas fa-circle text-blue-500 mr-2 text-xs"></i> 线程安全问题</li>
                        <li><i class="fas fa-circle text-blue-500 mr-2 text-xs"></i> 内存一致性问题</li>
                    </ul>
                </div>
            </div>
            
            <div class="bg-blue-50 p-6 rounded-lg mb-8">
                <div class="flex items-start">
                    <div class="flex-shrink-0 text-blue-600 text-2xl mr-4">
                        <i class="fas fa-lightbulb"></i>
                    </div>
                    <div>
                        <h3 class="text-xl font-bold mb-2">并发编程的优势</h3>
                        <p>通过并发编程，程序可以在多核处理器上并行执行多个任务，充分利用硬件资源，提高程序的处理效率和响应能力。</p>
                    </div>
                </div>
            </div>
            
            <div class="mermaid mb-12">
                graph TD
                    A[并发编程] --> B[多线程]
                    A --> C[任务调度]
                    A --> D[并发容器]
                    B --> E[Thread类]
                    B --> F[Runnable接口]
                    C --> G[Executor框架]
                    D --> H[ConcurrentHashMap]
                    D --> I[CopyOnWriteArrayList]
            </div>
        </section>
        
        <div class="divider"></div>
        
        <!-- Process & Thread Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-2 h-10 bg-blue-600 mr-4"></div>
                <h2 class="text-3xl font-bold">进程与线程基础</h2>
            </div>
            
            <p class="text-lg mb-6">在计算机科学中，<strong>进程</strong>和<strong>线程</strong>是操作系统管理计算机资源和调度任务的基本单位。理解它们的区别和联系，是学习并发编程的基础。</p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-project-diagram"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">进程（Process）</h3>
                    <p><strong>定义</strong>：进程是程序的一个实例，代表了计算机中正在执行的一个程序。每个进程都有自己的内存空间、数据、资源以及执行状态。</p>
                    <p class="mt-4"><strong>特性</strong>：</p>
                    <ul class="list-disc pl-5 mt-2 space-y-1">
                        <li>每个进程都有自己独立的内存空间</li>
                        <li>进程间通信需要通过特定机制</li>
                        <li>进程创建和销毁开销较大</li>
                    </ul>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-stream"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">线程（Thread）</h3>
                    <p><strong>定义</strong>：线程是进程中的一个执行单元，属于进程的一部分。每个进程至少有一个线程（主线程）。线程共享进程的资源。</p>
                    <p class="mt-4"><strong>特性</strong>：</p>
                    <ul class="list-disc pl-5 mt-2 space-y-1">
                        <li>线程间共享进程的内存空间</li>
                        <li>创建和销毁线程的开销较小</li>
                        <li>线程切换比进程切换更高效</li>
                    </ul>
                </div>
            </div>
            
            <h3 class="text-2xl font-bold mb-6">进程与线程的区别</h3>
            
            <div class="overflow-x-auto mb-8">
                <table class="comparison-table bg-white rounded-lg shadow-sm">
                    <thead>
                        <tr>
                            <th class="rounded-tl-lg">特性</th>
                            <th>进程</th>
                            <th class="rounded-tr-lg">线程</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><strong>资源占用</strong></td>
                            <td>每个进程有独立的资源</td>
                            <td>线程共享进程的资源</td>
                        </tr>
                        <tr>
                            <td><strong>开销</strong></td>
                            <td>创建和销毁进程的开销较大</td>
                            <td>创建和销毁线程的开销较小</td>
                        </tr>
                        <tr>
                            <td><strong>通信</strong></td>
                            <td>进程间通信较复杂</td>
                            <td>线程间通信较简单</td>
                        </tr>
                        <tr>
                            <td><strong>稳定性</strong></td>
                            <td>进程崩溃不会影响其他进程</td>
                            <td>线程崩溃可能导致整个进程崩溃</td>
                        </tr>
                        <tr>
                            <td class="rounded-bl-lg"><strong>调度和切换</strong></td>
                            <td>进程切换的开销较大</td>
                            <td class="rounded-br-lg">线程切换的开销较小</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-xl font-bold mb-4">进程的生命周期</h3>
                    <div class="mermaid">
                        graph LR
                            A[新建] --> B[就绪]
                            B --> C[运行]
                            C --> D[阻塞]
                            D --> B
                            C --> E[终止]
                    </div>
                </div>
                <div>
                    <h3 class="text-xl font-bold mb-4">线程的生命周期</h3>
                    <div class="mermaid">
                        graph LR
                            A[新建] --> B[就绪]
                            B --> C[运行]
                            C --> D[阻塞]
                            D --> B
                            C --> E[死亡]
                    </div>
                </div>
            </div>
        </section>
        
        <div class="divider"></div>
        
        <!-- Thread Creation Section -->
        <section id="examples" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-2 h-10 bg-blue-600 mr-4"></div>
                <h2 class="text-3xl font-bold">线程的创建与启动</h2>
            </div>
            
            <p class="text-lg mb-6">在 Java 中，线程是实现并发编程的核心。Java 提供了两种主要的方式来创建和启动线程：<strong>继承 <code>Thread</code> 类</strong> 和 <strong>实现 <code>Runnable</code> 接口</strong>。</p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-code-branch"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">继承 Thread 类</h3>
                    <div class="code-block p-4 rounded mb-4">
                        <pre><code class="text-sm">class MyThread extends Thread {
    @Override
    public void run() {
        System.out.println("Thread is running.");
    }
}

public class ThreadDemo {
    public static void main(String[] args) {
        MyThread thread = new MyThread();
        thread.start(); // 启动线程
    }
}</code></pre>
                    </div>
                    <p class="text-sm">通过继承 <code>Thread</code> 类，并重写 <code>run()</code> 方法来指定线程执行的任务。调用 <code>start()</code> 方法来启动线程。</p>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-project-diagram"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">实现 Runnable 接口</h3>
                    <div class="code-block p-4 rounded mb-4">
                        <pre><code class="text-sm">class MyRunnable implements Runnable {
    @Override
    public void run() {
        System.out.println("Runnable thread is running.");
    }
}

public class RunnableDemo {
    public static void main(String[] args) {
        MyRunnable myRunnable = new MyRunnable();
        Thread thread = new Thread(myRunnable);
        thread.start(); // 启动线程
    }
}</code></pre>
                    </div>
                    <p class="text-sm"><code>MyRunnable</code> 类实现了 <code>Runnable</code> 接口，重写了 <code>run()</code> 方法。创建 <code>Thread</code> 对象时传入 <code>Runnable</code> 实例。</p>
                </div>
            </div>
            
            <div class="bg-white p-6 rounded-lg shadow-sm mb-8">
                <h3 class="text-xl font-bold mb-4"><i class="fas fa-info-circle text-blue-500 mr-2"></i> start() 和 run() 方法的区别</h3>
                <ul class="list-disc pl-5 space-y-2">
                    <li><strong>start()</strong>：用于启动线程。它会创建一个新的线程，并调用该线程的 <code>run()</code> 方法。<code>start()</code> 方法只能调用一次。</li>
                    <li><strong>run()</strong>：用于定义线程要执行的任务。如果直接调用 <code>run()</code> 方法，它会在当前线程中执行，而不是启动一个新的线程。</li>
                </ul>
            </div>
            
            <div class="mermaid">
                graph TD
                    A[创建线程] --> B[继承Thread类]
                    A --> C[实现Runnable接口]
                    B --> D[重写run方法]
                    C --> D
                    D --> E[调用start方法]
                    E --> F[新建状态]
                    F --> G[就绪状态]
                    G --> H[运行状态]
                    H --> I[阻塞状态]
                    I --> G
                    H --> J[死亡状态]
            </div>
        </section>
        
        <div class="divider"></div>
        
        <!-- Synchronization Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-2 h-10 bg-blue-600 mr-4"></div>
                <h2 class="text-3xl font-bold">同步与并发控制</h2>
            </div>
            
            <p class="text-lg mb-6">在并发编程中，多个线程可能同时访问共享资源，导致数据的不一致和程序错误。为了避免这种情况，需要使用同步机制来控制线程的访问顺序，确保数据的正确性。</p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-lock"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">synchronized 关键字</h3>
                    <div class="code-block p-4 rounded mb-4">
                        <pre><code class="text-sm">public class Counter {
    private int count = 0;

    // 同步方法
    public synchronized void increment() {
        count++;
    }

    public int getCount() {
        return count;
    }
}</code></pre>
                    </div>
                    <p><code>increment()</code> 方法加上了 <code>synchronized</code>，确保该方法在同一时刻只能由一个线程执行。</p>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-lock-open"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">Lock 接口</h3>
                    <div class="code-block p-4 rounded mb-4">
                        <pre><code class="text-sm">import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Counter {
    private int count = 0;
    private Lock lock = new ReentrantLock();

    public void increment() {
        lock.lock();  // 加锁
        try {
            count++;
        } finally {
            lock.unlock();  // 解锁
        }
    }

    public int getCount() {
        return count;
    }
}</code></pre>
                    </div>
                    <p>使用 <code>ReentrantLock</code> 显式加锁和解锁，提供了更细粒度的控制。</p>
                </div>
            </div>
            
            <h3 class="text-2xl font-bold mb-6">并发控制的高级技术</h3>
            
            <div class="grid md:grid-cols-3 gap-6 mb-8">
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-balance-scale"></i>
                    </div>
                    <h4 class="text-lg font-bold mb-3">乐观锁与悲观锁</h4>
                    <p><strong>悲观锁</strong>：采用 <code>synchronized</code> 或 <code>Lock</code>，假设数据会发生冲突，每次操作都需要加锁。</p>
                    <p class="mt-2"><strong>乐观锁</strong>：假设数据不会冲突，只在数据发生冲突时才处理，如 CAS 操作。</p>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-atom"></i>
                    </div>
                    <h4 class="text-lg font-bold mb-3">原子操作</h4>
                    <div class="code-block p-4 rounded mb-2">
                        <pre><code class="text-sm">import java.util.concurrent.atomic.AtomicInteger;

public class Counter {
    private AtomicInteger count = new AtomicInteger(0);

    public void increment() {
        count.incrementAndGet();
    }
}</code></pre>
                    </div>
                    <p>原子变量类提供无锁的线程安全操作。</p>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-traffic-light"></i>
                    </div>
                    <h4 class="text-lg font-bold mb-3">信号量</h4>
                    <div class="code-block p-4 rounded mb-2">
                        <pre><code class="text-sm">Semaphore semaphore = new Semaphore(3);

semaphore.acquire();
try {
    // 临界区代码
} finally {
    semaphore.release();
}</code></pre>
                    </div>
                    <p>用于限制并发访问资源数量。</p>
                </div>
            </div>
            
            <div class="mermaid">
                graph LR
                    A[并发控制] --> B[锁机制]
                    A --> C[原子操作]
                    A --> D[信号量]
                    A --> E[线程池]
                    B --> F[synchronized]
                    B --> G[Lock接口]
                    C --> H[AtomicInteger]
                    C --> I[AtomicLong]
                    D --> J[Semaphore]
                    E --> K[ExecutorService]
                    E --> L[ForkJoinPool]
            </div>
        </section>
        
        <div class="divider"></div>
        
        <!-- Sync vs Async Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-2 h-10 bg-blue-600 mr-4"></div>
                <h2 class="text-3xl font-bold">同步与异步</h2>
            </div>
            
            <p class="text-lg mb-6"><strong>同步</strong>和<strong>异步</strong>是并发编程中常见的两种执行方式，它们描述了不同的执行模型，尤其是在任务执行和处理的时间上有所区别。</p>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-sync-alt"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">同步（Synchronous）</h3>
                    <p><strong>特征</strong>：</p>
                    <ul class="list-disc pl-5 mt-2 mb-4 space-y-1">
                        <li>当前任务必须等待前一个任务完成</li>
                        <li>操作执行期间会阻塞当前线程</li>
                        <li>实现简单直观</li>
                    </ul>
                    <div class="code-block p-4 rounded">
                        <pre><code class="text-sm">// 同步读取文件内容
String content = readFile("file.txt");
System.out.println(content);</code></pre>
                    </div>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-random"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">异步（Asynchronous）</h3>
                    <p><strong>特征</strong>：</p>
                    <ul class="list-disc pl-5 mt-2 mb-4 space-y-1">
                        <li>当前任务发起后不需要等待</li>
                        <li>通过回调或事件机制处理结果</li>
                        <li>提高程序的并发性</li>
                    </ul>
                    <div class="code-block p-4 rounded">
                        <pre><code class="text-sm">// 异步请求数据
asyncRequestData(url, new Callback() {
    @Override
    public void onResponse(String data) {
        System.out.println("Received data: " + data);
    }
});</code></pre>
                    </div>
                </div>
            </div>
            
            <h3 class="text-2xl font-bold mb-6">同步与异步的对比</h3>
            
            <div class="overflow-x-auto">
                <table class="comparison-table bg-white rounded-lg shadow-sm">
                    <thead>
                        <tr>
                            <th class="rounded-tl-lg">特点</th>
                            <th>同步（Synchronous）</th>
                            <th class="rounded-tr-lg">异步（Asynchronous）</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><strong>执行方式</strong></td>
                            <td>当前任务必须等待前一个任务完成</td>
                            <td>当前任务发起后立即返回</td>
                        </tr>
                        <tr>
                            <td><strong>阻塞</strong></td>
                            <td>阻塞当前线程直到任务完成</td>
                            <td>非阻塞，线程可以继续执行其他任务</td>
                        </tr>
                        <tr>
                            <td><strong>任务返回</strong></td>
                            <td>返回结果时必须等待任务完成</td>
                            <td>通过回调等方式获取结果</td>
                        </tr>
                        <tr>
                            <td><strong>复杂度</strong></td>
                            <td>实现简单</td>
                            <td>需要回调、事件监听等机制</td>
                        </tr>
                        <tr>
                            <td><strong>适用场景</strong></td>
                            <td>适合简单、顺序执行的任务</td>
                            <td>适合 I/O 密集型、需要高并发的任务</td>
                        </tr>
                        <tr>
                            <td class="rounded-bl-lg"><strong>性能</strong></td>
                            <td>可能导致效率低</td>
                            <td class="rounded-br-lg">提高并发能力，效率高</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </section>
        
        <!-- Concurrency Tools Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-2 h-10 bg-blue-600 mr-4"></div>
                <h2 class="text-3xl font-bold">并发控制的基本工具</h2>
            </div>
            
            <div class="grid md:grid-cols-3 gap-6 mb-8">
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-lock"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">锁（Lock）</h3>
                    <p>保证在同一时刻只有一个线程能够访问共享资源</p>
                    <div class="mt-4">
                        <span class="inline-block bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded mr-2">synchronized</span>
                        <span class="inline-block bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded mr-2">ReentrantLock</span>
                        <span class="inline-block bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded">ReadWriteLock</span>
                    </div>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-exchange-alt"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">条件变量（Condition）</h3>
                    <p>用于线程间的通信和协调</p>
                    <div class="code-block p-4 rounded mt-4">
                        <pre><code class="text-sm">Condition condition = lock.newCondition();
condition.await();  // 等待
condition.signal(); // 通知</code></pre>
                    </div>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-atom"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">原子变量</h3>
                    <p>保证在并发环境中对变量的操作是原子的</p>
                    <div class="mt-4">
                        <span class="inline-block bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded mr-2">AtomicInteger</span>
                        <span class="inline-block bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded mr-2">AtomicLong</span>
                        <span class="inline-block bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded">AtomicBoolean</span>
                    </div>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-traffic-light"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">信号量</h3>
                    <p>用于限制并发访问资源数量</p>
                    <div class="code-block p-4 rounded mt-4">
                        <pre><code class="text-sm">Semaphore semaphore = new Semaphore(3);
semaphore.acquire();
try {
    // 临界区代码
} finally {
    semaphore.release();
}</code></pre>
                    </div>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-tasks"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">阻塞队列</h3>
                    <p>支持线程间协作的线程安全队列</p>
                    <div class="mt-4">
                        <span class="inline-block bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded mr-2">ArrayBlockingQueue</span>
                        <span class="inline-block bg-blue-100 text-blue-800 text-xs px-2 py-1 rounded">LinkedBlockingQueue</span>
                    </div>
                </div>
                
                <div class="card bg-white p-6 rounded-lg">
                    <div class="feature-icon">
                        <i class="fas fa-users-cog"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4">线程池</h3>
                    <p>高效管理和复用线程资源</p>
                    <div class="code-block p-4 rounded mt-4">
                        <pre><code class="text-sm">ExecutorService executor = 
    Executors.newFixedThreadPool(10);
executor.submit(() -> {
    // 执行任务
});</code></pre>
                    </div>
                </div>
            </div>
            
            <div class="mermaid">
                graph TB
                    A[并发控制工具] --> B[锁机制]
                    A --> C[原子变量]
                    A --> D[信号量]
                    A --> E[线程池]
                    A --> F[阻塞队列]
                    A --> G[条件变量]
                    B --> H[synchronized]
                    B --> I[ReentrantLock]
                    C --> J[AtomicInteger]
                    D --> K[Semaphore]
                    E --> L[ExecutorService]
                    F --> M[ArrayBlockingQueue]
                    G --> N[Condition]
            </div>
        </section>
    </main>
    
    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-10">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-sm">探索编程世界的精彩</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition duration-300">
                        <i class="fas fa-link mr-2"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="mt-8 pt-6 border-t border-gray-800 text-center text-sm">
                <p>© 2023 技术小馆. 保留所有权利.</p>
            </div>
        </div>
    </footer>
    
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
        
        // 添加滚动动画
        const animateOnScroll = () => {
            const elements = document.querySelectorAll('.card, .animated-underline');
            elements.forEach(element => {
                const elementPosition = element.getBoundingClientRect().top;
                const screenPosition = window.innerHeight / 1.3;
                
                if (elementPosition < screenPosition) {
                    element.style.opacity = '1';
                    element.style.transform = 'translateY(0)';
                }
            });
        };
        
        // 初始化元素样式
        document.querySelectorAll('.card').forEach(card => {
            card.style.opacity = '0';
            card.style.transform = 'translateY(20px)';
            card.style.transition = 'all 0.5s ease';
        });
        
        document.querySelectorAll('.animated-underline').forEach(el => {
            el.style.display = 'inline-block';
        });
        
        // 监听滚动事件
        window.addEventListener('scroll', animateOnScroll);
        window.addEventListener('load', animateOnScroll);
    </script>
</body>
</html>
```